<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<script src="js/mui.min.js"></script>
		<link href="css/mui.min.css" rel="stylesheet" />
		<script type="text/javascript" charset="utf-8">
			//			mui.init();
		</script>
	</head>

	<body>
		<div class="mui-content">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>用户名</label>
					<input id="username" type="text" class="mui-input-clear" placeholder="请输入用户名" value="zhangsan">
				</div>
				<div class="mui-input-row">
					<label>密码</label>
					<input id="password" type="password" class="mui-input-password" placeholder="请输入密码">
				</div>
				<div class="mui-button-row">
					<button id="confirm" type="button" class="mui-btn mui-btn-primary">确认</button>
					<button id="cancel" type="button" class="mui-btn mui-btn-danger">取消</button>
				</div>
			</form>
			<script>
				mui.init();
				mui.plusReady(function() {
					var username = document.getElementById("username");
					var password = document.getElementById("password");
					var confirm = document.getElementById("confirm");

					confirm.addEventListener("tap", function() {
						mui.ajax('http://86.100.25.80:8080/login', {
							data: {
								username: username.value,
								password: password.value
							},
							dataType: 'json', //服务器返回json格式数据
							type: 'post', //HTTP请求类型
							timeout: 10000, //超时时间设置为10秒；
							headers: {
								'Content-Type': 'application/json'
							},
							success: function(data) {
								console.log(JSON.stringify(data));
								if(data.success) {
									var user = {
										username:username.value,
										password:password.value
									};
									
									plus.storage.setItem('user', JSON.stringify(user));
									
									mui.openWindow({
										url: 'login_success.html',
										id: 'success_page'
									});
								} else {
									mui.openWindow({
										url: 'login_failed.html',
										id: 'failed_page'
									});
								}
							},
							error: function(xhr, type, errorThrown) {
								console.log("错误");
								//异常处理；
								console.log("错误" + xhr.responseText);
							}
						});
					});
				});
			</script>
		</div>
	</body>

</html>